﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;

namespace UniMana.Data
{
    public static class Training_TrainingProgram_ScheduleData
    {
       
        public static IQueryable GetByTrainingProramKey(DBMain nData, int i_trainingProgramKey)
        {
            var listTrainingProgramSchedule =
                                  from t_tpd in nData.m_DCSave.Training_TrainingProgram_Details
                                  from t_tps in nData.m_DCSave.Training_TrainingProgram_Schedules
                                  from t_s in nData.m_DCSave.Training_Subjects
                                  from c_st in nData.m_DCSave.Catalogue_SubjectTypes
                                  from t_sg in nData.m_DCSave.Training_SubjectGroups
                                  where
                                  t_tpd.Training_TrainingProgramKey == i_trainingProgramKey &&

                                  t_tpd.Training_TrainingProgramKey == t_tps.Training_TrainingProgramKey &&
                                  t_tpd.Training_SubjectKey == t_tps.Training_SubjectKey &&
                                  t_tpd.Training_SubjectGroupKey == t_sg.Training_SubjectGroupKey &&
                                  t_tpd.Training_SubjectKey == t_s.Training_SubjectKey &&
                                  t_tpd.Catalogue_SubjectTypeKey == c_st.Catalogue_SubjectTypeKey
                                  select new
                                  {
                                      t_tps.Training_TrainingProgramKey,
                                      t_tps.Training_SubjectKey,
                                      t_tps.Catalogue_TermKey,
                                      SubjectGroup = t_sg.Name,
                                      SubjectID = t_s.ID,
                                      SubjectName = t_s.Name,
                                      TotalCredits = t_s.Credits1 + t_s.Credits2 + t_s.Credits3,
                                      SubjectType = c_st.Name
                                  };

            return listTrainingProgramSchedule;
        }

        #region Chi --Hòa
        /// <summary>
        /// Lấy danh sách phân kỳ theo ctđt
        /// </summary>
        /// <param name="nTrainingProgramSchedule"></param>
        /// <param name="nTrainingProgramDetail"></param>
        /// <param name="nSubject"></param>
        /// <param name="nSubjectType"></param>
        /// <param name="nSubjectGroup"></param>
        /// <param name="i_trainingProgramKey">Mã chương trình đào tạo</param>
        /// <returns></returns>
        public static IQueryable GetByTrainingProramKey(
            this Table<Training_TrainingProgram_Schedule> nTrainingProgramSchedule,
            Table<Training_TrainingProgram_Detail> nTrainingProgramDetail,
            Table<Training_Subject> nSubject,
            Table<Catalogue_SubjectType> nSubjectType,
            Table<Training_SubjectGroup> nSubjectGroup,
            Table<Training_Subject_Class> nSubject_Class,
            int i_trainingProgramKey,
            bool GetStatus = false)
        {
            var listTrainingProgramSchedule =
                                  from t_tpd in nTrainingProgramDetail
                                  from t_tps in nTrainingProgramSchedule
                                  from t_s in nSubject
                                  from c_st in nSubjectType
                                  from t_sg in nSubjectGroup
                                  where
                                  t_tpd.Training_TrainingProgramKey == i_trainingProgramKey &&

                                  t_tpd.Training_TrainingProgramKey == t_tps.Training_TrainingProgramKey &&
                                  t_tpd.Training_SubjectKey == t_tps.Training_SubjectKey &&
                                  t_tpd.Training_SubjectGroupKey == t_sg.Training_SubjectGroupKey &&
                                  t_tpd.Training_SubjectKey == t_s.Training_SubjectKey &&
                                  t_tpd.Catalogue_SubjectTypeKey == c_st.Catalogue_SubjectTypeKey
                                  select new
                                  {
                                      t_tps.Training_TrainingProgramKey,
                                      t_tps.Training_SubjectKey,
                                      t_tps.Catalogue_TermKey,
                                      SubjectGroup = t_sg.Name,
                                      SubjectID = t_s.ID,
                                      SubjectName = t_s.Name,
                                      t_s.Credits1,
                                      t_s.Credits2,
                                      t_s.Credits3,
                                      t_s.Credits4,
                                      t_s.Credits5,
                                      TotalCredits = t_s.Credits1 +
                                                     t_s.Credits2 +
                                                     t_s.Credits3 +
                                                     t_s.Credits4 +
                                                     t_s.Credits5,
                                      SubjectType = c_st.Name,
                                      t_s.Subject_SameKey
                                  };
            //if (GetStatus)
            //{
            //    var InClass = from list in listTrainingProgramSchedule
            //                  join sj_c in nSubject_Class
            //                            on list.Training_SubjectKey
            //                            equals sj_c.Training_SubjectKey
            //                  select list;
            //}
            return listTrainingProgramSchedule;
        }

        #endregion
    }
}
